extends IGuiable


class_name Moveable
"""
可拖动的UI适配
"""


var is_dragging: bool = false
var drag_offset: Vector2 = Vector2.ZERO


func on_gui_input(event: InputEvent) -> void:
    if event is InputEventMouseButton:
        var mouse_event = event as InputEventMouseButton
        if mouse_event.button_index == MOUSE_BUTTON_LEFT:
            if not is_dragging and mouse_event.pressed:
                is_dragging = true
                drag_offset = wrapper.get_viewport().get_mouse_position() - wrapper.position
            if is_dragging and not mouse_event.pressed:
                is_dragging = false
    if event is InputEventMouseMotion and is_dragging:
        wrapper.position = wrapper.get_viewport().get_mouse_position() - drag_offset
